package kin.system.util;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;

import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;

public class ClassUtil {
	public static boolean isBaseDataType(Class clazz) {
		return (clazz.equals(String.class) || clazz.equals(Integer.class)
				|| clazz.equals(Byte.class) || clazz.equals(Long.class)
				|| clazz.equals(Float.class) || clazz.equals(Character.class)
				|| clazz.equals(Short.class) || clazz.equals(BigDecimal.class)
				|| clazz.equals(BigInteger.class) || clazz.isInterface()
				|| clazz.equals(Boolean.class) || clazz.equals(Date.class) 
				|| clazz.isPrimitive());
	}
	
	public static Object getValue(Object obj, String fieldName) {
		EvaluationContext context = new StandardEvaluationContext(obj);
		ExpressionParser parser = new SpelExpressionParser();
		Expression exp = parser.parseExpression(fieldName);
		return exp.getValue(context);
	}
	

	
	
}
